//
// Created by zhouwd on 2019/8/1.
//

#include "media_init_notify.h"

int _MEDIA_INIT_NOTIFY::init(JavaVM *javaVM, jobject callbackObj, jmethodID onChangedMD) {
    this->javaVM = javaVM;
    this->callbackObj = callbackObj;
    this->onChangedMD = onChangedMD;

    if (javaVM){
        int getEnvStat = javaVM->GetEnv((void **)&java, JNI_VERSION_1_6);
        ALOGE("_MEDIA_VIDEO_FRAME_NOTIFY > init > getEnvStat > %d", getEnvStat);
        if (getEnvStat == JNI_EDETACHED){
            JavaVMAttachArgs args = { JNI_VERSION_1_6, 0, 0};
            javaVM->AttachCurrentThread(&java, &args);
        } else if (getEnvStat == JNI_EVERSION){

        }
    }

    return 0;
}

int _MEDIA_INIT_NOTIFY::destory() {

    return 0;
}

int _MEDIA_INIT_NOTIFY::notifyInit(int sampleRateInHz, int channelConfig, int audioFormat, int videoWidth, int videoHeight) {
    if (java != nullptr) {
        java->CallVoidMethod(callbackObj, onChangedMD, sampleRateInHz, channelConfig, audioFormat, videoWidth, videoHeight);
    } else {
        ALOGE("_MEDIA_VIDEO_FRAME_NOTIFY > updateFrame > null");
    }
    return 0;
}
